package com.bootdo.app.controller;

import com.bootdo.app.common.msg.Response;
import com.bootdo.app.vo.miniprogram.BannerVo;
import com.bootdo.common.constant.CommonConstant;
import com.bootdo.common.domain.DictDO;
import com.bootdo.common.service.DictService;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author huangyalou
 * @date 2021/2/7 20:23
 * @desc
 */
@Api("banner 相关api")
@RestController
@RequestMapping(value = "/app/set")
public class BannerController {

    @Autowired
    private DictService dictService;


    @ApiOperation("查询所有banner")
    @PostMapping("/find_banner_all")
    public Response find_list(){
        DictDO dictDO = dictService.findOneByType(CommonConstant.SYSTEM_SET);
        if(dictDO==null){
            return  Response.fail("数据异常");
        }
        List<DictDO> dictDOList = Lists.newArrayList();
        if("1".equals(dictDO.getValue())){
          dictDOList = dictService.listByType(CommonConstant.SYSTEM_SET_1);
        }else{
            dictDOList = dictService.listByType(CommonConstant.SYSTEM_SET_2);
        }
        List<BannerVo> bannerVoList = dictDOList.parallelStream().map(v->{
            BannerVo bannerVo = new BannerVo();
            bannerVo.setUrl(v.getValue());
            bannerVo.setRule(v.getDescription());
            return bannerVo;
        }).collect(Collectors.toList());
     return Response.success(bannerVoList);
    }


    @ApiOperation("查询所有海报背景")
    @PostMapping("/find_poster_all")
    public Response findPosterAll(){
        List<DictDO> dictDOList = dictService.listByType(CommonConstant.SYSTEM_SET_POSTER);
        List<String > list = dictDOList.parallelStream().map(v->{
            return v.getValue();
        }).collect(Collectors.toList());
     return Response.success(list);
    }

    @ApiOperation("判断显示 邀请好友还是领券1:  邀请好友  2：签到")
    @PostMapping("/find_status")
    public Response findStatus(){
        DictDO dictDO = dictService.findOneByType(CommonConstant.SYSTEM_SET);
        if(dictDO==null){
            return  Response.fail("数据异常");
        }
        return Response.success(dictDO.getValue());
    }


}
